"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/3/3 10:01
@Description :  面向对象
多态
 不同的对象调用相同的方法，表现出不同的状态，称之为多态
 父类的引用指向子类对象

  Cat(Animal)   Cat  Animal

 解耦和

 在父类中可以经方法声明称抽象方法 抽象方法可以没有方法体
"""

from abc import ABC, abstractmethod

'''
  类一旦继承了ABC  该类不可再被实例化
  后续的子类中  必须要将抽象方法覆盖后 才能实例化对象
'''
# 宠物
class Animal(ABC):

    name = None
    age = None

    @abstractmethod
    def bark(self):
        pass

class Cat(Animal):
    # def __init__(self, name, age):
    #     self.name = name
    #     self.age = age

    # def bark(self):
    #     print('小猫喵喵叫')

    pass


class Dog(Animal):

    def bark(self):
        print('小狗汪汪叫')
    pass


class Food:
    name = None


#  食物
class Fish(Food):
    pass


class Bone(Food):
    pass


#  主人类
class Master:
    '''
     def feeding_cat(self, cat: Cat, fish: Fish):
        print(f'主人饲养宠物猫,cat.name = {cat.name},cat.age = {cat.age},食物:{fish.name}')

    def feeding_dog(self, dog: Dog, bone: Bone):
        print(f'主人饲养宠物狗dog.name = {dog.name},dog.age = {dog.age},食物:{bone.name}')

    '''

    def feeding(self, animal: Animal, food: Food):
        animal.bark()
        print(f'主人饲养宠物,name = {animal.name},age = {animal.age},food.name = {food.name}')


master = Master()

cat:Cat = Cat()
cat.name = 'tom'
cat.age = 2
fish = Fish()
fish.name = '小鱼'

# master.feeding_cat(cat, fish)
dog:Dog = Dog()
dog.name = '小狗'
dog.age = 1

bone = Bone()
bone.name = '骨头'
# master.feeding_dog(dog, bone)
# master.feeding_cat(dog, bone)


#  判定数据类型
# print(isinstance(cat,Animal))
# print(isinstance(dog,Animal))
# print(isinstance(dog,Dog))
# print(isinstance(cat,Cat))
# print(isinstance(cat,Dog))

print('---------------------------------')
# animal = Animal()
# print(isinstance(animal, Cat))
print('---------------------------------')


# animal: Animal = Cat('tom', 2)
# animal:Animal = dog
# print(animal.name)
# print(animal.age)


# master.feeding(cat)
master.feeding(dog, bone)
master.feeding(cat, fish)
